<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ECMAScript基础(深入)</title>
</head>
<body>
    <script>
        ;(function(){
            // 原型 -> 继承
            function Teacher(){
                this.name = 'Mr. Li';
                this.tSkill = 'JAVA';
            }
            Teacher.prototype = {
                pSkill: 'JS/JQ'
            }
            var teacher = new Teacher();
            console.log(teacher);

            function Student(){
                Teacher.call(this);
                this.name = 'Mr. Wang';
            }
            // 将T原型属性赋值给S原型属性，指针指向公共原型
            Student.prototype = Teacher.prototype;
            // 如果给S或T任意一个赋值，都会改变公共原型
            Student.prototype.age = 18;

            var student = new Student();
            console.log(student);
        })()

        ;(function(){
            // 圣杯继承
            function Teacher(){
                this.name = 'Mr. Li';
                this.tSkill = 'JAVA';
            }
            Teacher.prototype = {
                pSkill: 'JS/JQ'
            }
            var teacher = new Teacher();
            console.log(teacher);

            function Student(){
                this.name = 'Mr. Wang';
            }

            function Buffer(){
                Teacher.call(this);
            }
            Buffer.prototype = Teacher.prototype;
            Student.prototype = new Buffer();

            Student.prototype.age = 100;
            var student = new Student();
            console.log(student);
        })()

        ;(function(){
            // 封装圣杯继承
            function Teacher(){
                this.name = 'Mr. Li';
                this.tSkill = 'JAVA';
            }
            Teacher.prototype = {
                pSkill: 'JS/JQ'
            }

            function Student(){
                this.name = 'Mr. Wang';
            }

            // 会被覆盖
            // Student.prototype = {
            //     test: 10
            // }

            function inhert(Target, Origin){
                function Buffer(){
                    Origin.call(this);
                }
                Buffer.prototype = Origin.prototype;
                Target.prototype = new Buffer();
                Target.prototype.constructor = Target;
                Target.prototype.super_class = Origin;
            }

            inhert(Student, Teacher);
            var teacher = new Teacher();
            console.log(teacher);
            var student = new Student();
            Student.prototype.age = 100;
            console.log(student);
        })()

        // 模块化开发
        // 圣杯模式通用函数
        // 如果交给一个变量，不会销毁
        var inhert = (function(){
            function Buffer(){
                Origin.call(this);
            }
            return function(Target, Origin){
                Buffer.prototype = Origin.prototype;
                Target.prototype = new Buffer();
                Target.prototype.constructor = Target;
                Target.prototype.super_class = Origin;
            }
        })()
    </script>
</body>
</html>